package com.yl.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yl.dao.IUsersDao;
import com.yl.model.Users;
@Service
public class UsersService implements IUsersService {

	
	@Resource
	private IUsersDao usersDao;
	/**
	 *前台用户登录
	 */
	@Override
	public Users login(Users users) {
		return usersDao.login(users);
	}

	/**
	 *显示个人信息
	 */
	@Override
	public Users findById(int user_id) {
		return usersDao.findById(user_id);
	}
	
	
	
	/**
	 *注册
	 */
	@Override
	public int register(Users users) {
		return usersDao.register(users);
	}

	/**
	 *修改密码
	 */
	@Override
	public int editPwd(String oldPwd, String newPwd,Users users) {
		int n = 0;
		//1、先判断原密码是否正确
		if(oldPwd.equals(users.getUser_password())) {
			n = usersDao.editPwd(newPwd,users.getUser_id());
		}
		
		return n;
	}

	/**
	 *修改个人信息
	 */
	@Override
	public int edit(Users users) {
		return usersDao.edit(users);
	}
	
	/**
	 *查询所有用户
	 */
	@Override
	public Map<String,Object> findAll() {
		List<Users> list = usersDao.findAll();
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("count", list.size());
		map.put("data", list);
		return map;
	}

	/**
	 *将用户默认地址设为订单收获地址
	 */
	@Override
	public int findAddressId(int user_id) {
		return usersDao.findAddressId(user_id);
	}

}
